//
//  ZQTabBar.m
//  BuDeJie
//
//  Created by zuqiu on 17/10/27.
//  Copyright © 2017年 zuqiu. All rights reserved.
//

#import "ZQTabBar.h"

@interface ZQTabBar ()
@property (nonatomic, weak) UIButton *publishButton;

@end
@implementation ZQTabBar

//- (instancetype)initWithFrame:(CGRect)frame {
//    if (self = [super initWithFrame:frame]) {
//        // 设置tabBar的背景图片
//        [self setBackgroundImage:[UIImage imageNamed:@"tabbar-light"]];
//        
//
//    }
//    return self;
//}

- (UIButton *)publishButton
{
    if (_publishButton == nil) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [btn setImage:[UIImage imageNamed:@"tabBar_publish_icon"] forState:UIControlStateNormal];
        [btn setImage:[UIImage imageNamed:@"tabBar_publish_click_icon"]  forState:UIControlStateHighlighted];
        [btn sizeToFit];
        [self addSubview:btn];
        _publishButton = btn;

    }
    return _publishButton;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    NSLog(@"%@", self.subviews);
    NSInteger count = self.items.count;
    CGFloat btnW = self.zq_width / (count + 1);
    CGFloat btnH = self.zq_height;
    CGFloat x = 0;
    int i = 0;
    for (UIView *tabBarButton in self.subviews) {
        if ([tabBarButton isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
            tabBarButton.frame = CGRectMake(x, 0, btnW, btnH);
            if (i == 2) {
                i += 1;
            }
            x= i * btnW;
            tabBarButton.frame = CGRectMake(x, 0, btnW, btnH);
            NSLog(@"%@",NSStringFromCGRect(tabBarButton.frame));
            i++;
        }
    }
    self.publishButton.center = CGPointMake(self.zq_width*  0.5, self.zq_height * 0.5);
}

@end
